package com.example.bus.demos.web.service.Impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.bus.demos.web.entity.BusRoute;
import com.example.bus.demos.web.mapper.BusRouteMapper;
import com.example.bus.demos.web.service.BusRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BusRouteServiceImpl implements BusRouteService {
    @Autowired
    private BusRouteMapper busRouteMapper;
    @Override
    public List<BusRoute> getAllRoutes() {
        return busRouteMapper.selectList(null);
    }
    @Override
    public BusRoute getRouteById(Long id) {
        return busRouteMapper.selectById(id);
    }
    @Override
    public void addRoute(BusRoute busRoute) {
        busRouteMapper.insert(busRoute);
    }
    @Override
    public void updateRoute(BusRoute busRoute) {
        busRouteMapper.updateById(busRoute);
    }
    @Override
    public void deleteRoute(Long id) {
        busRouteMapper.deleteById(id);
    }
    @Override
    public List<BusRoute> searchByRouteName(String routeName) {
        LambdaQueryWrapper<BusRoute> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusRoute::getRouteName, routeName);
        return busRouteMapper.selectList(queryWrapper);
    }
    @Override
    public List<BusRoute> searchByRouteNumber(String routeNumber) {
        LambdaQueryWrapper<BusRoute> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusRoute::getRouteNumber, routeNumber);
        return busRouteMapper.selectList(queryWrapper);
    }
}
